package com.shao.web;
import com.google.gson.Gson;
import com.shao.utils.Methods;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: SJP
 * Date: 2021/6/3
 * Time: 16:17
 * Description: No Description
 */
public class RequestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String file =  req.getParameter("file");
        System.out.println(file);
        String datafromFile = Methods.getDatafromFile(file);
        System.out.println(datafromFile);
        // json格式的字符串
        Gson gson = new Gson();
        String data = gson.toJson(datafromFile);
        req.setAttribute("data1",123);
        req.setAttribute("data",datafromFile);
        req.getRequestDispatcher("/json.jsp").forward(req,resp);

    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
